﻿using FrameworkCore.Configurations;
using FrameworkCore.Interfaces;
using FrameworkCore.Modules.Startups;
using Infrastructure.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Infrastructure.Startups;


/// <summary>
/// 雪花ID生成设置
/// </summary>
public partial class NetModulerSnowFlakeIdStartup : INetModulerStartup
{
    /// <summary>
    /// 添加和配置任何中间件
    /// </summary>
    /// <param name="services">服务描述符集合</param>
    /// <param name="configuration">应用程序的配置</param>
    public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        GenerateIdSettings snowFlakeSettings = configuration.GetSection(GenerateIdSettings.Key).Get<GenerateIdSettings>()!;
        services.AddSingleton<IGenerateIdService>(new GenerateIdService(snowFlakeSettings.WorkerId, snowFlakeSettings.DataCenterId, snowFlakeSettings.IsSnowFlakeId));
    }

    /// <summary>
    /// 配置添加的中间件的使用
    /// </summary>
    /// <param name="application">用于配置应用程序请求管道的构建器</param>
    public void Configure(IApplicationBuilder application)
    {
    }

    /// <summary>
    /// 获取此启动配置实现的顺序
    /// </summary>
    public int Order => 9;  //最好在数据库生成之前
}
